package com.android.andsec ;

import android.app.Activity ;
import android.content.SharedPreferences ;
import android.content.SharedPreferences.Editor ;
import android.os.Bundle ;
import android.view.View ;
import android.view.View.OnClickListener ;
import android.view.Window ;
import android.widget.ImageButton ;

public class MessageActivity extends Activity implements OnClickListener {
	
	public ImageButton isEnabled ;
	public ImageButton setting ;
	public ImageButton phone_log ;
	public ImageButton sms_log ;
	public ImageButton blacklist ;
	public ImageButton whitelist ;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE) ;
		setContentView(R.layout.sms) ;
		isEnabled = (ImageButton) findViewById(R.id.turn_or_off) ;
		setting = (ImageButton) findViewById(R.id.setting) ;
		phone_log = (ImageButton) findViewById(R.id.phone_log) ;
		sms_log = (ImageButton) findViewById(R.id.sms_log) ;
		blacklist = (ImageButton) findViewById(R.id.blacklist) ;
		whitelist = (ImageButton) findViewById(R.id.whitelist) ;
		this.findViewById(R.id.turn_or_off).setOnClickListener(this) ;
		this.findViewById(R.id.setting).setOnClickListener(this) ;
		this.findViewById(R.id.phone_log).setOnClickListener(this) ;
		this.findViewById(R.id.sms_log).setOnClickListener(this) ;
		this.findViewById(R.id.blacklist).setOnClickListener(this) ;
		this.findViewById(R.id.whitelist).setOnClickListener(this) ;
		checkpreferences() ;
	}
	
	private boolean checkpreferences() {
		boolean changed = false ;
		final SharedPreferences prefs = getSharedPreferences( smsAPI.pref_name , 0 ) ;
		final Editor editor = prefs.edit() ;
		if( prefs.getString( smsAPI.isEnabled , "" ).length()==0 ) {
			editor.putString( smsAPI.isEnabled, smsAPI.OFF ) ;
			changed = true ;
		}
		editor.commit() ;
		return changed ;
	}
	
	private void refresh() {
		final SharedPreferences prefs = getSharedPreferences( smsAPI.pref_name , 0 ) ;
		final Editor editor = prefs.edit() ;
		String a =  prefs.getString(smsAPI.isEnabled, smsAPI.OFF ) ;
		if( a.equals(smsAPI.OFF) ) {
			isEnabled.setImageResource(R.drawable.on) ;
			editor.putString(smsAPI.isEnabled, smsAPI.ON) ;
		} else {
			isEnabled.setImageResource(R.drawable.off) ;
			editor.putString(smsAPI.isEnabled, smsAPI.OFF) ;
		}
		editor.commit() ;
	}

	@Override
	public void onClick(View v) {
		switch( v.getId() ) {
		case R.id.turn_or_off:
			refresh() ;
			break ;
		case R.id.setting:
			break ;
		case R.id.phone_log:
			break ;
		case R.id.sms_log:
			break ;
		case R.id.blacklist:
			break ;
		case R.id.whitelist:
			break ;
		}
	}
}
